<?php
/**
 * 后台管理
 * hsx
 * 2022/7/16
 */
namespace App\Http\Controllers\web;

use App\Http\Controllers\Controller;
use App\Repository\RepositoryInterface\GroupInterface;
use Illuminate\Http\Request;


//拼团类
class GroupController extends Controller
{
    //
    protected $group;


    public function __construct(GroupInterface $group){
        $this->group = $group;
    }

    /**
     * 拼团列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function groupList(Request $request){
        try {

            $size = $request->get('pageSize');

            return $this->group->groupList($size);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 添加拼团
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addGroup(Request $request){
        try {

            $post = $request->post();
            //验证
            return  $this->group->addGroup($post);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 删除
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delGroup(Request $request){
        try {

            $id = $request->get('id');

            return $this->group->delGroup($id);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 拼团详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function groupDetails(Request $request){
        try {

            $id = $request->get('id');

            return  $this->group->groupDetails($id);

        }catch (\Exception $exception){
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 拼团修改
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function groupAlter(Request $request)
    {
        try {
            $post = $request->post();
            return parent::success('success',$result);

        }catch (Exception $exception){
            return parent::error($exception->getMessage());
        }
    public function GroupProductAddition(Request $request)
    {
        $param=$request->post();
        $file=$request->post('content');
        $this->group->GroupProductAddition($param);
            return $this->group->groupAlter($post);
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }

    /**
     *添加拼团商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addCollageGoods(Request $request){
        try {

            $post = $request->post();

            return  $this->group->addCollageGoods($post);


        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 删除拼团商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delCollageGoods(Request $request){
        try {
            $id = $request->get('id');
            return  $this->group->delCollageGoods($id);

        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 拼团商品详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function detailsCollageGoods(Request $request){
        try {

            $id = $request->get('id');
            return  $this->group->detailsCollageGoods($id);
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }

    /**
     * 修改拼团商品
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateCollageGoods(Request $request){
        try {
            $post = $request->post();
            return  $this->group->updateCollageGoods($post);
        } catch (\Exception $exception) {
            return parent::error($exception->getMessage());
        }
    }
}
